﻿<!--学生查看文章详情-->
<style>
	.center2 {
		width: 960px;
		min-height: 560px;
		display: inline-block;
		border-radius: 5px;
		border: 1px solid #c3c3c0;
		padding: 0 20px;
		position: relative;
	}
	
	.text-h3 {
		font-size: 32px;
		font-weight: 600;
		text-align: justify;
		text-justify: newspaper;
		word-break: break-all;
	}
	
	.text-h4 {
		padding: 10px 10px;
		font-size: 14px;
		color: #858585;
		padding-bottom: 20px;
		border-bottom: 1px solid #C3C3C0;
		cursor: pointer;
	}
	
	.main {
		padding: 10px 0;
		font-size: 16px;
		text-align: justify;
		text-justify: newspaper;
		word-break: break-all;
	}
	
	#button_div {
		position: absolute;
		right: 0;
		bottom: 10px;
	}
	
	#dianzan {
		margin-left: 10px;
		margin-right: 10px;
	}
</style>

<div class="center2" id="center2">

</div>

<script>
	scroll(0, 0);

	var arid = $.session.get('arid');

	var myajax = $.ajax({
		xhrFields: {
			withCredentials: true
		},
		type: 'GET',
		url: getFullURL('get-article'),
		data: {
			arid: arid
		},
		success: function(data) {
			console.log(data)
			var str = `
                    <h3 class="text-left text-h3">` + data.article.title + `</h3>
                    <h5 class="text-h4" id="article" value="` + data.article.sno + `">作者：` + data.name + ` &nbsp;&nbsp;发布时间：` + data.article.createTime + ` &nbsp;&nbsp;点赞数：` + data.article.dianzan + `</h5>
                    <input type="hidden" id="fabuzhe_sno" value='` + data.article.sno + `'/>
                    <div class="main">` + data.article.content + `</div>
                    <div class="text-right" id="button_div">
                    	<button type="button" class="btn btn-primary" id="cancel">返&emsp;回</button>
                    	<button type="button" id="dianzan" value="` + data.article.arid + `" class="btn btn-primary">点&emsp;赞</button>
                   	</div>
                    `;

			$('#center2').append(str);

			$('#cancel').click(function() {
				$.session.set("a_flag", -1);
				$('.center').html('');
				$('.center').load('./articlelist.html');
			})
		},
		error: function(err) {
			alert("请求异常，请重新登录！", function() {
				$(location).attr('href', './login.html');
			})
		}
	})

	//myajax请求完毕时执行
	$.when(myajax).done(function() {
		$('#article').click(function(e) {
			var sno = $(this).attr("value");
			$.session.set("sno_flag", -1); //-1代表非登录用户
			$.session.set("sno2", sno);
			$('.center').html('');
			$('.center').load('./student.html');
		})

		$('#dianzan').click(function(e) {
			$.ajax({
				xhrFields: {
					withCredentials: true
				},
				type: 'POST',
				url: getFullURL('dianzan-article'),
				data: {
					arid: $(this).val()
				},
				success: function(data) {
					if(data.status == 0) {
						alert("点赞成功！");
						$('.center').html('');
						$('.center').load('./article.html');
						//window.location.href="./home.html"
					} else {
						alert("点赞失败！");
					}
				},
				error: function(err) {
					alert("请求异常，请重新登录！", function() {
						$(location).attr('href', './login.html');
					})
				}
			})
		})
	})
</script>